import { useAddressStore } from '@/store/index.js'
// 返回当前的日期时间
export const currentDate = () => {
	const day = new Date()
	const y = day.getFullYear()
	const m = day.getMonth()
	const d = day.getDate()
	const time = y + '年' + (m + 1>0 ? m + 1 : '0' + m + 1) + '月' +( d>0 ? d: '0' + d) + '日'
	return time
}
// 返回当前的日期时间
export const currentDay = () => {
	const date = new Date()
	const day = date.getDay()
  const week = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
	return week[day]
}
// 获取当前经纬度
/**
 * @returns latitude  经度
 * @returns longitude 维度
 * @returns address   详细地址
*/
export const getLoaction = async () => {
	const { SETLONLAT } = useAddressStore()
	const res = await uni.getLocation({ type: 'gcj02', altitude:true, geocode:true, })
	let loaction = {
		longitude: res.longitude,
		latitude: res.latitude,
		address: res.address
	}
	return loaction
}

// 秒转时分秒
export const formateTime = (time) => {
	const h = parseInt(time / 3600)
	const minute = parseInt(time / 60 % 60)
	const second = Math.ceil(time % 60)
	
	const hours = h < 10 ? '0' + h : h
	const formatSecond = second > 59 ? 59 : second
	return `${hours > 0 ? `${hours}:` : '00:'}${minute < 10 ? '0' + minute : minute}:${formatSecond < 10 ? '0' + formatSecond : formatSecond}`
}

// 查看图片预览
export const previewImg = (urls) => {
	const urlArr = []
	urls.forEach(item => {
		if(item.url) urlArr.push(item.url)
	})
	
	uni.previewImage({
		urls:urlArr.length?urlArr:urls,
		loop: true,
		indicator: 'number',
	})
}
// 关闭图片预览
export const closePreImg = () => {
	uni.closePreviewImage({})
}